package cn.imvc.app.controllers;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.imvc.app.models.ActivityModel;

@Controller
@RequestMapping("/activity")
public class ActivityControllerImpl implements ActivityController {
	@Autowired
	private ActivityModel activityModel;
	@RequestMapping("/list.htm")
	public String listActivitiesByOrderAmount(Integer orderAmount,Model model) {
		List<Object[]> activityInfoList = activityModel.getActivitiesInfoByOrderAmount(orderAmount);
		model.addAttribute("activityInfoList", activityInfoList);
		if(activityInfoList!=null&&activityInfoList.size()>0){
			Object activityId = activityInfoList.get(0)[0];
			if(activityId!=null){
				List<Object[]> goodsInfoList = activityModel.getGoodsInfoByActivityId((Integer)activityId);
				model.addAttribute("goodsInfoList", goodsInfoList);
			}
		}
		return "order/pc_gift_content";
	}
	@RequestMapping("/getGoodsInfos.htm")
	public String pcGetGoodsInfoByActivityId(Integer activityId, Model model) {
		//TODO  check 该活动id 是否在该订单符合的活动中。 
		List<Object[]> goodsInfoList = activityModel.getGoodsInfoByActivityId(activityId);
		model.addAttribute("goodsInfoList", goodsInfoList);
		return "order/pc_gift_content";
	}
	@RequestMapping("/getGoodsInfos.html")
	public String getGoodsInfoByActivityId(Integer activityId,Model model) {
		//TODO  check 该活动id 是否在该订单符合的活动中。 
		List<Object[]> goodsInfoList = activityModel.getGoodsInfoByActivityId(activityId);
		model.addAttribute("goodsInfoList", goodsInfoList);
		return "order/gift_content";
	}

}
